﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using YAPL.Language.Ast;
using YAPL.Language.SourceParser.Helpers;
using YAPL.Language.SourceParser.Helpers;
using YAPL.Util;

namespace YAPL.Language.SourceParser.XML.NodeParsers {
	public class XmlUnaryParser : XmlExpressionParser {
		public XmlUnaryParser(XmlInputParser parser) : base(parser) {}
		public override Expression ParseNode(XElement node) {
			Require.True(node.Elements().Count() == 1);
			var operandNode = node.Elements().First();
			Require.NotNull(operandNode);
			var op = node.Attribute(XmlNames.UnaryOperatorAttribute);
			Require.NotNull(op);
			return Expressions.Unary(Parser.ParseNode(operandNode), OperatorHelper.ParseUnaryOperator(op.Value));
		}
	}
}
